from datetime import datetime
from app import db


class UserTag(db.Model):
    """用户标签表"""
    __tablename__ = 'user_tags'
    
    id = db.Column(db.Integer, primary_key=True)
    user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False, comment='用户ID')
    tag_name = db.Column(db.String(50), nullable=False, comment='标签名称')
    tag_type = db.Column(db.String(20), nullable=False, comment='标签类型：system系统,hobby兴趣')
    
    # 时间戳
    created_at = db.Column(db.DateTime, default=datetime.utcnow, comment='创建时间')
    
    def to_dict(self):
        """转换为字典"""
        return {
            'id': self.id,
            'user_id': self.user_id,
            'tag_name': self.tag_name,
            'tag_type': self.tag_type,
            'created_at': self.created_at.strftime('%Y-%m-%d %H:%M:%S') if self.created_at else None
        }
    
    def __repr__(self):
        return f'<UserTag {self.tag_name}>' 